import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const userInfo = defineStore('userstore',()=>{
    const uid = ref(0);
    const name = ref("");
    const avatar = ref("");
    const email = ref("");
    const isLogined = ref(false);

    function setuid(id:number){
        uid.value = id;
    }

    function setname(username:string){
        name.value = username;
    }

    function setemail(em:string) {
        email.value = em;
    }
    
    function setLogin(login:boolean){
        isLogined.value = login;
    }

    function setavatar(ava:string){
        avatar.value = ava;
    }
    return{
        uid,
        name,
        avatar,
        email,
        isLogined,
        setuid,
        setname,
        setemail,
        setLogin,
        setavatar
    }
},

    {
        persist:{
            storage:sessionStorage,
            key:'userInfo',
            paths:['name','avatar','uid','isLogined']
        }
    }

)